<?php

require("fpdf.php");

$connect = mysql_connect("localhost", "root", "") or die("error");
mysql_select_db("erpymes") or die("eroor connecting Database");
/*

  $queryget = mysql_query ("select * from report ORDER BY Transaction_Number DESC LIMIT 5" ) or die (" error with table"); */
$todayDate = date('Y-m-d');
$queryget = mysql_query("select * from warehouse_product ") or die(" error with table");

$number_of_products = mysql_numrows($queryget);

$column_Customername = "";
$column_Transaction = "";
$column_Time = "";
$column_Weight = "";
$column_Price = "";
$column_Date = "";
$total = 0;
$total1 = 0;


while ($row = mysql_fetch_assoc($queryget)) {
    $id = $row['id'];
//id, name, description, brand_id, model_id, buy, sale, category_id, unit_id, location, created_at, updated_at
    $Customername = $row ['name'];
    $Transaction_Number = $row ['brand_id'];
    $Price = $row ['model_id'];
    $Weight = $row ['category_id'];
    $date = $row ['unit_id'];
    $time = $row ['created_at'];
    $column_Customername = $column_Customername . $Customername . "\n";
    $column_Transaction = $column_Transaction . $Transaction_Number . "\n";
    $column_Time = $column_Time . $time . "\n";
    $column_Weight = $column_Weight . $Weight . "\n";
    $column_Price = $column_Price . $Price . "\n";
    $column_Date = $column_Date . $date . "\n";

    $total = $total + $Price;
    $total1 = $total1 + $Weight;
}


$pdf = new FPDF();
$pdf->AddPage();

class PDF extends FPDF {

//Page header
    /*
      function Header()
      {
      //Logo
      $this->Image('trans.jpeg',10,8,160);
      //Arial bold 15
      $this->SetFont('Arial','B',15);
      //Move to the right
      $this->Cell(80);
      //Title
      /*$this->Cell(30,10,'Title',1,0,'C');
      //Line break
      $this->Ln(20);
      } */

//Page footer
    function Footer() {
        //Position at 1.5 cm from bottom
        $this->SetY(-15);
        //Arial italic 8
        $this->SetFont('Arial', 'I', 8);
        //Page number
        $this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
        $this->setX(10);
        $this->Cell(0, 10, 'Confidential', 0, 0, 'L');
    }

}

//Instanciation of inherited class
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times', '', 12);
/* for($i=1;$i<=40;$i++)
  $pdf->Cell(0,10,'Printing line number '.$i,0,1); */

$pdf->setX(50);
$pdf->sety(32);
$pdf->cell(25, 6, $column_Date);

//Fields Name position
$Y_Fields_Name_position = 40;
//Table position, under Fields Name
$Y_Table_Position = 46;

//First create each Field Name
//Gray color filling each Field Name box

$pdf->SetFillColor(232, 232, 232);

//Bold Font for Field Name
$pdf->SetFont('Arial', 'B', 8);
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(30);
$pdf->Cell(25, 6, 'Trans.Number', 1, 0, 'L', 1);
$pdf->SetX(55);
$pdf->Cell(50, 6, 'Name', 1, 0, 'L', 1);
$pdf->SetX(105);
$pdf->Cell(25, 6, 'Time', 1, 0, 'L', 1);
$pdf->SetX(130);
$pdf->Cell(25, 6, 'Weight', 1, 0, 'L', 1);
$pdf->SetX(155);
$pdf->Cell(25, 6, 'Price', 1, 0, 'L', 1);
$pdf->Ln();
//Now show the 3 columns
$pdf->SetFont('Arial', '', 6);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(30);
$pdf->MultiCell(35, 6, $column_Transaction, 1, 'false');
$pdf->SetY($Y_Table_Position);
$pdf->SetX(55);
$pdf->MultiCell(50, 6, $column_Customername, 1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(105);
$pdf->MultiCell(25, 6, $column_Time, 1, 'R');
$pdf->SetY($Y_Table_Position);
$pdf->SetX(130);
$pdf->MultiCell(25, 6, $column_Weight, 1, 'R');
$pdf->SetX(130);
$pdf->MultiCell(25, 6, 'Kg ' . $total1, 1, 'R');
$pdf->SetY($Y_Table_Position);
$pdf->SetX(155);
$pdf->MultiCell(25, 6, $column_Price, 1, 'R');
$pdf->SetX(155);
$pdf->MultiCell(25, 6, 'Rs ' . $total, 1, 'R');

$i = 0;
$pdf->SetY($Y_Table_Position);
while ($i < $number_of_products) {
    $pdf->SetX(45);
    $pdf->MultiCell(120, 6, '', 1);
    $i = $i + 1;
}

$pdf->Output();
?>

